/* eslint-disable */

const {createProxyMiddleware} = require('http-proxy-middleware');
const {CASTOKEN, SERVER_ENV} = process.env;

const {CASTOKEN: LOCALCASTOKEN} = require('../gct.env.json');

const server2url = {
    'rd': 'http://127.0.0.1',
    'test': `https://${SERVER_ENV}-udata.baijia.com`,
    'beta': `https://${SERVER_ENV}-udata.baijia.com`,
    'prod': 'https://udata.baijia.com',
}

module.exports = function(app) {
    if (SERVER_ENV) {
        app.use(
            ['/api', '/nsapi'],
            createProxyMiddleware({
                target: server2url[SERVER_ENV],
                changeOrigin: true,
                headers: {
                    cookie: `_const_d_jsession_id_=${CASTOKEN || LOCALCASTOKEN}`
                },
                pathRewrite: { '^': '' },
            })
        );
    }
};
